﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DataAccessLayer;
using DataAccessLayer.RolesDataSetTableAdapters;
using System.Data;
using System.Collections.Specialized;
using RBS_Tools;

namespace BusinessLayer
{
    public class Roles
    {
        private static tbl_RolesTableAdapter TA_Roles = new tbl_RolesTableAdapter();
        private static RolesDataSet.tbl_RolesDataTable DT_Roles;

        public static DataTable GetRoles(string Username)
        {
            //return TA_Roles.GetRoleByUsername(Username).AsEnumerable().ToDictionary(row => row["RoleID"].ToString(), row => new string[] { "Rolecode", "Rolename" }.ToDictionary(col => col, col => row[col].ToString()));
            return TA_Roles.GetRoleByUsername(Username);
        }

        public static DataTable GetRoles()
        {
            return TA_Roles.GetRolesData();
        }

        public static bool Exists(string roleCode)
        {
            return TA_Roles.IsRoleExists(roleCode) == 0 ? false : true;
        }

        public static Guid GetRoleID(string roleCode)
        {
            return TA_Roles.GetRolesData().Where(col => col.Rolecode == roleCode).Select(col => col.RoleID).FirstOrDefault();
        }

        public static string GetRoleCode(Guid roleID)
        {
            return TA_Roles.GetRolesData().Where(col => col.RoleID == roleID).Select(col => col.Rolecode).FirstOrDefault();
        }

        public static DataTable GetRoleByUserID(string UserID)
        {
            return TA_Roles.GetRolesByMemberID(Guid.Parse(UserID));
        }

        public static void AddRole(string roleName, string roleCode, string desc)
        {
            TA_Roles.Insert(Guid.NewGuid(), roleName, roleCode, desc, true, DateTime.Now, DateTime.Now);
        }
    }
}
